from django.db import models


class Log(models.Model):
    message = models.CharField(max_length=4096)
    time = models.DateTimeField(auto_now=True)


class Student(models.Model):
    name = models.CharField(max_length=20)
    sex = models.IntegerField()
    age = models.IntegerField()
    cellphone = models.CharField(max_length=20)
    birth = models.DateTimeField()
    email = models.CharField(max_length=120, null=True)

    def __str__(self):
        return self.name


class Book(models.Model):
    name = models.CharField(max_length=20)
    price = models.IntegerField()
    year = models.IntegerField()
    author = models.CharField(max_length=20)

    def __str__(self):
        return self.name

    def __repr__(self):
        return self.name


class Father(models.Model):
    name = models.CharField(max_length=128)

    def __str__(self):
        return self.name


class Child(models.Model):
    name = models.CharField(max_length=128)
    father = models.ForeignKey(Father, on_delete=models.DO_NOTHING)

    def __str__(self):
        return self.name


class Tag(models.Model):
    desc = models.CharField(max_length=128)

    def __str__(self):
        return self.desc


class Article(models.Model):
    title = models.CharField(max_length=128)
    tag = models.ManyToManyField(Tag)

    def __str__(self):
        return self.title


class Private(models.Model):
    keyid = models.CharField(max_length=128)

    def __str__(self):
        return self.keyid


class Public(models.Model):
    keyid = models.CharField(max_length=128)
    private = models.OneToOneField('Private', null=True)

    def __str__(self):
        return self.keyid


class Teacher(models.Model):
    gender = models.IntegerField(default=1)
    comment = models.CharField(max_length=20, null=True)
